Skip to content

fix: task leak, unsafe auto-install, fragile exception handling + routing tests#71

Merged
Otoru merged 1 commit intomainfrom
fix/task-leak-and-routing-improvements
Mar 21, 2026
Merged

fix: task leak, unsafe auto-install, fragile exception handling + routing tests#71
Otoru merged 1 commit intomainfrom
fix/task-leak-and-routing-improvements

Conversation

@Otoru
Copy link
Owner

@Otoru Otoru commented Mar 21, 2026

Summary

  • Task leak in dispatcher: tasks created by dispatch_to_handlers had no strong reference and could be garbage-collected mid-execution. Exceptions in handlers were silently dropped. Added an optional task_set parameter to keep tasks alive and a done_callback to log exceptions and remove completed tasks. Protocol now holds a handler_tasks: set and cancels all of them on stop().
  • Unsafe auto pip install in LoadBalancer: _create_redis_client ran pip install redis via subprocess when the package was missing. Replaced with an ImportError with a clear message pointing to pip install genesis[redis].
  • Fragile exception handling in Inbound: start() had an inner try/except that detected tracer errors by string-matching ("tracer" not in str(e).lower()). The OTel API spec guarantees start_as_current_span never raises — the block was removed.
  • Routing tests: ChannelRoutingStrategy, GlobalRoutingStrategy, CompositeRoutingStrategy and dispatch_to_handlers had no test coverage. Added tests/test_routing.py with 18 tests.

Test plan

  • poetry run pytest tests/test_routing.py -v — 18/18 passed
  • poetry run pytest tests/ -v — 186/186 passed
  • poetry run black --check genesis/ tests/ examples/ — no changes
  • poetry run mypy — no issues
  • poetry run tox — py312 passed (py310/py311 not installed locally)

…ng, and add routing tests

- dispatcher: track handler tasks in a set to prevent GC mid-execution and
  log unhandled exceptions via done callbacks
- base: add handler_tasks set, pass it to dispatch_to_handlers, cancel all
  handler tasks on stop()
- load_balancer: replace silent pip auto-install with ImportError pointing to
  pip install genesis[redis]
- inbound: remove inner try/except that tested tracer errors by string matching;
  OTel API guarantees start_as_current_span never raises
- tests: add test_routing.py with 18 tests covering ChannelRoutingStrategy,
  GlobalRoutingStrategy, CompositeRoutingStrategy, and dispatch_to_handlers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Otoru Otoru merged commit c8070f7 into main Mar 21, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant